package org.spring.blog.controller.portal;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.spring.blog.response.ResponseResult;
import org.spring.blog.response.ResponseState;
import org.spring.blog.service.IFriendLinkService;
import org.spring.blog.service.ILooperService;
import org.spring.blog.service.IWebSizeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/portal/web_size_info")
public class WebSizeInfoPortalApi {


    @Autowired
    private IFriendLinkService friendLinkService;

    @Autowired
    private ILooperService looperService;

    @Autowired
    private IWebSizeInfoService webSizeInfoService;


    /**
     * 获取网站信息的方法
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取网站信息的方法")
    @ApiResponses(@ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message))
    @GetMapping("/title")
    public ResponseResult getWebSizeTitle() {
        return webSizeInfoService.getWebSizeTitle();
    }

    /**
     * 获取网站访问量的方法
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取网站访问量的方法")
    @ApiResponses(@ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message))
    @GetMapping("/view_count")
    public ResponseResult getWebSizeViewCount() {
        return webSizeInfoService.getWebSizeViewCount();
    }

    /**
     * 获取轮播图列表的方法
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取轮播图列表的方法")
    @ApiResponses(@ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message))
    @GetMapping("/loop")
    public ResponseResult getLoops() {
        return looperService.list();
    }

    /**
     * 获取友情链接列表的方法
     *
     * @return 自定义返回对象
     */
    @ApiOperation("获取友情链接列表的方法")
    @ApiResponses(@ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message))
    @GetMapping("/friend_link")
    public ResponseResult getFriendLinks() {
        return friendLinkService.list();
    }

    /**
     * 增加一个访问量的方法
     * <p>
     * 用户访问页面时增加一个访问量到 redis 数据库
     * 用户获取总的访问量时将 redis 中的数据 添加到 mysql 持久层
     */
    @ApiOperation("增加一个访问量的方法")
    @ApiResponses(@ApiResponse(code = ResponseState.success_code, message = ResponseState.success_message))
    @PutMapping("/view_count")
    public void updateViewCount() {
        webSizeInfoService.updateViewCount();
    }
}
